﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ToyChat.BuiltinModules
{
    /// <summary>
    /// This dialog can be used to ask the user for a Channel name and Password set when joining channels
    /// </summary>
    public partial class JoinChannelDialog : UserControl, IDialog
    {
        /// <summary>
        /// Initializes a new instance of <see cref="JoinChannelDialog"/>
        /// </summary>
        public JoinChannelDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or Sets the text displayed in the channel name text box
        /// </summary>
        public string ChannelName
        {
            get { return this.nameBox1.Text; }
            set { this.nameBox1.Text = value; }
        }

        /// <summary>
        /// Gets or Sets the password contained in the password box
        /// </summary>
        public string Password
        {
            get { return this.pwBox1.Password; }
            set { this.pwBox1.Password = value; }
        }

        /// <summary>
        /// Called when the Cancel button is clicked
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The arguments of the event</param>
        private void cancelBtn1_Click(object sender, RoutedEventArgs e)
        {
            if (this.Cancel != null)
                this.Cancel.Invoke(this, e);
        }

        /// <summary>
        /// Called when the Ok button is clicked
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The arguments of the event</param>
        private void okBtn1_Click(object sender, RoutedEventArgs e)
        {
            if (this.OK != null)
                this.OK.Invoke(this, e);
        }

        /// <summary>
        /// This event is fired whenever the user clicks the OK button of this dialog
        /// </summary>
        public event RoutedEventHandler OK;

        /// <summary>
        /// This event is fired whenever the user clicks the Cancel button of this dialog
        /// </summary>
        public event RoutedEventHandler Cancel;

        /// <summary>
        /// Gets the main input field of this dialog
        /// </summary>
        public IInputElement MainInput
        {
            get { return string.IsNullOrEmpty(this.ChannelName) ? (IInputElement)this.nameBox1 : (IInputElement)this.pwBox1; }
        }
    }
}
